﻿using Oracle.ManagedDataAccess.Client;
using System.Data;
using System.Text;
using WMSSyncData.Model.WMSModel;
using WMSSyncData.Utils;

namespace WMSSyncData.DAL.Oracle
{
    public class Tddev101DAL : BaseOracleDAL<WMS_T_InStockRMRows>
    {

        public int UpdateStatus(DataTable dt)
        {
            StringBuilder sb = new StringBuilder();
            //sb.AppendLine("begin");
            foreach (DataRow dr in dt.Rows)
            {
                var text = dr["Text"].ToString();
                if (!text.Contains("WMS已处理"))
                {
                    text = text + ";WMS已处理";
                }
                var sql = "UPDATE TTDDEV101101 set  t$status=1,t$text='" + text + "' where  t$pono='" + dr["RowNo"].ToString() + "' and t$orno='" + dr["RelatedBill"].ToString() + "' and t$sqnb='" + dr["OrderNo"].ToString() + "'";
                sb.AppendLine(sql);
            }
            //sb.AppendLine("end;");
            var resultSql = sb.ToString().Trim();
            var result = OracleDBHelper.ExecuteNonQuery(resultSql);
            return result;
        }

        public int UpdateText(DataTable dt)
        {
            StringBuilder sb = new StringBuilder();
            //sb.AppendLine("begin");
            foreach (DataRow dr in dt.Rows)
            {
                var text = dr["Text"].ToString();
                if (!text.Contains("WMS无法处理"))
                {
                    text = text + ";WMS无法处理";
                }
                var sql = "UPDATE TTDDEV101101 set  t$status=4,t$wdte1=SYSDATE,t$text='" + text + "'  where  t$pono='" + dr["RowNo"].ToString() + "' and t$orno='" + dr["RelatedBill"].ToString() + "' and t$sqnb='" + dr["OrderNo"].ToString() + "'";
                sb.AppendLine(sql);
            }
            //sb.AppendLine("end;");
            var resultSql = sb.ToString().Trim();
            var result = OracleDBHelper.ExecuteNonQuery(resultSql);
            return result;
        }


    }
}
